package com.example.learndevice.adapter

import android.graphics.BitmapFactory
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.example.learndevice.R

/**
 *
 * @Author： LJH
 * @Time： 2022/7/6
 * @description：
 */
class ShootingAdapter(pathList:ArrayList<String>):RecyclerView.Adapter<ShootingAdapter.ViewHolder>() {

    val mPathList:ArrayList<String> = pathList

    inner class ViewHolder(view:View):RecyclerView.ViewHolder(view){
        val img = view.findViewById<ImageView>(R.id.iv_shooting)
    }

    //指定子布局
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ShootingAdapter.ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_shooting,parent,false)
        return ViewHolder(view)
    }

    //给子布局item填充数据
    override fun onBindViewHolder(holder: ShootingAdapter.ViewHolder, position: Int) {
        val path = mPathList[position]
        holder.img.setImageBitmap(BitmapFactory.decodeFile(path))
    }

    override fun getItemCount(): Int = mPathList.size
}